
<script type="text/javascript">
function ChangeBulkAction(v)
{	
    if(document.getElementById(v).value == 'status')
   		document.getElementById("changestatus").style.display="inline";
   	else
   		document.getElementById("changestatus").style.display="none";
}
function ChangeStatus(s)
{
	if(document.getElementById("changestatus").value == 'unpublished')
   		document.getElementById("reason").style.display="inline";
   	else
   		document.getElementById("reason").style.display="none";
}

$(function() {
    $("table tr:nth-child(odd)").addClass("striped");//.hover(function(){this.removeClass("striped")});
});
</script>



<div style="background:#ffffff;">
<div style="width:100%;float: right" id = "paging">
<?if(isset($this->viewParams['adsList']) && count($this->viewParams['adsList']) > 0):?>
<?
$pageCount = ceil($this->viewParams['paginator']->getTotalItemCount()/$this->viewParams['paginator']->getItemCountPerPage());
?>
</div>
<form action="<?=$this->hvnUrl(array('module' => 'ads', 'action' => 'bulk'), 'nocontroller')?>" method="POST">
<table border = '1' width='650px'>
	<tr>
		<td></td>
		<td>ID</td>
		<td>Name</td>
		<td>Type</td>
		<td>Lang</td>
        <td>Themes</td>
        <td width="20%">Roles</td>
		<td>Region</td>
        <td width="10%">Operations</td>
	</tr>
	<? foreach ($this->viewParams['adsList'] as $row) :?>
	<?$metadata = unserialize($row['metadata'])?>
	<tr>
		<td>
			<input type="checkbox" value="<?=$row['id'] ?>" id="edit-ads-<?=$row['id'] ?>" name="ads[<?=$row['id'] ?>]"/>
		</td>
		<td>#<?=$row['id']?></td>
		<td><a href="<?=$this->hvnUrl(array('module' => 'ads', 'action' => 'view'), 'nocontroller')?>?id=<?=$row['id']?>" > <?=$row['name'] ?></a></td>
		<td><?=$row['type'] ?></td>
		<td><?=$row['languages'] ?></td>
        <td><?=str_replace(',' , '<br/>', $row['themes']) ?></td>
        <td><?=$row['roleNames'] ?></td>
        <td><?= str_replace(':' , ':<br/>', $metadata['region']) ?></td>
    	<td><a href="<?=$this->hvnUrl(array('module' => 'ads', 'action' => 'edit'), 'nocontroller')?>?id=<?=$row['id']?>">edit</a>
            <a href="<?=$this->hvnUrl(array('module' => 'ads', 'action' => 'delete'), 'nocontroller')?>?id=<?=$row['id']?>">delete</a>
        </td> 
	</tr>
			
	<?endforeach ?>
</table>
<? if ($pageCount > 1) :?>
	<?= $this->paginationControl($this->viewParams['paginator'], 'Sliding', '/modules/common/views/scripts/commonTheme/commonLang/common/clu-pagination-control.phtml',
							    array('searchUrl' => $this->viewParams['searchUrl'])); ?>
<?endif ?>
<?endif?>
<br />
<div  style="background-color:#EEEEEE">

Bulk Operation: 
<select name='bulkaction' id ="bulk" onchange = "ChangeBulkAction('bulk')">
<?if(true): //TODO: isadmin()?>
<option value='delete'> <?=t(31) ?> </option>
<?endif ?>
<option value='status'> <?=t(32) ?> </option>
</select>

<select name='changestatus' id ="changestatus" style=" display:none" onchange = "ChangeStatus('changestatus')">
	<option value='featured'> <?=t(33) ?> </option>
	<option value='published'> <?=t(34) ?> </option>
	<option value='queued'> <?=t(35) ?> </option>
	<option value='unpublished'> <?=t(36) ?> </option>
	<option value='deleted'> <?=t(37) ?> </option>
</select>
<input type="text" id="reason" style="display:none" name='reason'/>
<input type="submit" value="Apply" id="edit-submit" name="op"/>
</div>
</form>
<br/>
Create a new ads <a href="<?=$this->hvnUrl(array('module' => 'ads', 'action' => 'new'), 'nocontroller')?>"> here </a>
</div>